import copy
import hashlib
import json
import time
import datetime
import requests
import scrapy

from shiGuang.items import WkCommodityItem

from shiGuang.items import WkCustomerItem

from shiGuang.items import LuoShanCareItem

from shiGuang.items import WkCareItem


class WkSpider(scrapy.Spider):
    name = 'wk'
    # allowed_domains = ['http://www.xxx.com/']
    # start_urls = ['http://www.xxx.com/']
    username = input('请输入账号: ')
    password = input('请输入密码: ')
    encode_pwd = password.encode()  # 把字符串转为字节类型
    # 使用md5进行加密
    md5_pwd = hashlib.md5(encode_pwd)
    ai = {}
    b = 0

    def start_requests(self):
        """
        取登录页的cookie,并使用页面cookie登录
        :return:
        """
        url = 'http://www.xxx.com/'
        data = {
            'name': self.username,
            'password': self.md5_pwd.hexdigest()
        }
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
        }
        # 用request库去请求登录页,拿到cookie
        session = requests.session()
        session.post(url=url, headers=headers)
        page_cookie = session.cookies
        global cookie
        cookie = page_cookie.get_dict()
        print(cookie)
        # 登录使用cookie(这个网站的机制是登录页默认会有一个cookie,你登录带上这个cookie使其生效)
        yield scrapy.FormRequest(url=url, formdata=data, cookies=cookie, callback=self.start_pares)

    def start_pares(self, response):
        """
        获取分页
        :param response:
        :return:
        """
        url = 'http://www.xxx.com/'
        yield scrapy.Request(url=url, cookies=cookie, callback=self.parse)

    def parse(self, response):
        """
        处理列表页数据
        :param response:
        :return:
        """
        if response.status == 200:
            Selector_tr = response.xpath('//*[@id="table_div"]/table//tr')
            next_flag = False
            for tr in Selector_tr[1:]:
                time.sleep(0.2)
                # 获取列表页的举办时间
                data = tr.xpath('./td[10]/text()').get()
                if data:  # 判断时间是否为空
                    year_s, mon_s, day_s = data.strip().split('-')  # 分割年月日
                    first_date = datetime.date(int(year_s), int(mon_s), int(day_s))  # 格式化时间
                    second_date = datetime.date(2022, 10, 7)  # 比较的时间
                    if first_date >= second_date:  # 比较时间
                        # 详情页地址
                        client_url = 'http://www.xxx.com/' + tr.xpath('./td[2]/a/@href').get().strip()
                        # 新郎 td[6]/span/text()
                        if tr.xpath('./td[6]/span/text()').get():
                            bridegroom = tr.xpath('./td[6]/span/text()').get().strip()
                        else:
                            bridegroom = ''
                        # 新娘
                        if tr.xpath('./td[7]/span/text()').get():
                            bride = tr.xpath('./td[7]/span/text()').get().strip()
                        else:
                            bride = ''
                        # 来源  //*[@id="table_div"]/table/tbody/tr[2]/td[4]/text()
                        customer_source = tr.xpath('./td[4]/text()').get()
                        if customer_source:
                            customer_source = customer_source.strip()
                        # 审批状态
                        approval_status = tr.xpath('./td[@class="check_badge"]/text()').getall()
                        if approval_status[1].strip() == '通过':
                            approval_status = 1
                        elif approval_status[1].strip() == '待审':
                            approval_status = 2
                        else:
                            approval_status = 0
                        # 将列表的数据转在di字典中用于后面的取值
                        di = {'bridegroom': '未知', 'bride': '', 'customer_source': '', 'approval_status': '',
                              'data': data.strip()}
                        if bridegroom:
                            di['bridegroom'] = bridegroom
                        if bride:
                            di['bride'] = bride
                        if customer_source:
                            di['customer_source'] = customer_source
                        if approval_status:
                            di['approval_status'] = approval_status

                        yield scrapy.Request(url=client_url, cookies=cookie, callback=self.client_details,
                                             meta={'di': copy.deepcopy(di)}
                                             )  # dont_filter=True
                    else:
                        next_flag = True
                        continue
                    next_flag = True
                else:
                    next_flag = True
                    continue
            # 获取分页链接
            if next_flag:
                if response.xpath('//*[@id="tfoot_page"]/div[1]/div[2]/div/ul/li[3]/a/@href').get():
                    next_url = 'http://www.xxx.com/' + response.xpath(
                        '//*[@id="tfoot_page"]/div[1]/div[2]/div/ul/li[3]/a/@href').get()
                    # 请求分页接口
                    yield scrapy.Request(url=next_url, cookies=cookie, callback=self.parse)

    def basic_information(self, response, di):
        """
        基本信息
        :param response:
        :param di:
        :return:
        """
        basic_xpath = response.xpath('//*[@id="tab99"]/div/div[2]/div')
        a = 1
        # 查询基本信息中的所以字段
        for i in basic_xpath:
            # 循环取title和值
            if len(i.xpath('//*[@id="tab99"]/div/div[2]/div[{}]/label'.format(a))) >= 2:
                title = i.xpath('//*[@id="tab99"]/div/div[2]/div[{}]/label[1]/text()'.format(a)).get().strip()
                di['{}'.format(title)] = i.xpath(
                    '//*[@id="tab99"]/div/div[2]/div[{}]/div[1]/p/text()'.format(a)).get().strip()
                title = i.xpath('//*[@id="tab99"]/div/div[2]/div[{}]/label[2]/text()'.format(a)).get().strip()
                di['{}'.format(title)] = i.xpath(
                    '//*[@id="tab99"]/div/div[2]/div[{}]/div[2]/p/text()'.format(a)).get().strip()
                a = a + 1
            elif len(i.xpath('//*[@id="tab99"]/div/div[2]/div[{}]/label'.format(a))) < 2:
                if a == 3:
                    a = a + 1
                    pass
                else:  # 取单列数据
                    title = i.xpath('//*[@id="tab99"]/div/div[2]/div[{}]/label/text()'.format(a)).get().strip()
                    di['{}'.format(title)] = i.xpath(
                        '//*[@id="tab99"]/div/div[2]/div[{}]/div/p/text()'.format(a)).get().strip()
                    a = a + 1
        return di

    # 服务内容
    def service_content(self, response, service):
        """
        服务内容
        :param response:
        :param service:
        :return:
        """
        service_xpath = response.xpath('//*[@id="tab99"]/div/div[4]/div')
        a = 1
        for i in service_xpath:
            if len(i.xpath('//*[@id="tab99"]/div/div[4]/div[{}]/label'.format(a))) == 2:
                # //*[@id="tab99"]/div/div[4]/div[1]/label[1]
                title = i.xpath('//*[@id="tab99"]/div/div[4]/div[{}]/label[1]/text()'.format(a)).get().strip()
                service['{}'.format(title)] = i.xpath(
                    '//*[@id="tab99"]/div/div[4]/div[{}]/div[1]/p/text()'.format(a)).get().strip()
                title = i.xpath('//*[@id="tab99"]/div/div[4]/div[{}]/label[2]/text()'.format(a)).get().strip()
                if a == len(service_xpath):
                    service['{}'.format(title)] = i.xpath(
                        '//*[@id="tab99"]/div/div[4]/div[{}]/div[2]/p/a/text()'.format(a)).get().strip()
                else:
                    service['{}'.format(title)] = i.xpath(
                        '//*[@id="tab99"]/div/div[4]/div[{}]/div[2]/p/text()'.format(a)).get().strip()
                a = a + 1
        return service

    def fee_payment(self, response, service_fee_payment):
        """
        服务费用支付
        :param response:
        :param service_fee_payment:
        :return:
        """
        payment_xpath = response.xpath('//*[@id="tab99"]/div/div[6]/div')
        a = 1
        for i in payment_xpath:
            if len(i.xpath('//*[@id="tab99"]/div/div[6]/div[{}]/label'.format(a))) == 2:
                # //*[@id="tab99"]/div/div[4]/div[1]/label[1]
                title = i.xpath('//*[@id="tab99"]/div/div[6]/div[{}]/label[1]/text()'.format(a)).get().strip()
                service_fee_payment['{}'.format(title)] = i.xpath(
                    '//*[@id="tab99"]/div/div[6]/div[{}]/div[1]/p/text()'.format(a)).get().strip()
                title = i.xpath('//*[@id="tab99"]/div/div[6]/div[{}]/label[2]/text()'.format(a)).get().strip()
                service_fee_payment['{}'.format(title)] = i.xpath(
                    '//*[@id="tab99"]/div/div[6]/div[{}]/div[2]/p/text()'.format(a)).get().strip()
                a = a + 1
        return service_fee_payment

    def other_information(self, response, other):
        """
        处理其他信息
        :param response:
        :param other:
        :return:
        """
        other_xpath = response.xpath('//*[@id="tab99"]/div/div[8]/div')
        a = 1
        for i in other_xpath:
            title = i.xpath('//*[@id="tab99"]/div/div[8]/div[{}]/label[1]/text()'.format(a)).get().strip()
            other['{}'.format(title)] = i.xpath(
                '//*[@id="tab99"]/div/div[8]/div[{}]/div[1]/p/span/text()'.format(a)).get().strip()
            if len(i.xpath('//*[@id="tab99"]/div/div[8]/div[{}]/label'.format(a))) == 2:
                title = i.xpath('//*[@id="tab99"]/div/div[8]/div[{}]/label[2]/text()'.format(a)).get().strip()
                other['{}'.format(title)] = i.xpath(
                    '//*[@id="tab99"]/div/div[8]/div[{}]/div[2]/p/span/text()'.format(a)).get().strip()
            a = a + 1
        return other

    def client_details(self, response):
        """
        处理取值
        :param response:
        :return:
        """
        item = WkCareItem()
        di = response.meta['di']  # 基本信息
        di = self.basic_information(response, di)
        service = {}  # 服务信息
        service = self.service_content(response, service)
        # 服务费用支付
        service_fee_payment = {}
        service_fee_payment = self.fee_payment(response, service_fee_payment)
        other = {}
        other = self.other_information(response, other)
        # 首付款
        service_fee_payment['首付款'], service_fee_payment['首付时间'] = self.advance_method(service_fee_payment['首付款'])
        # 尾款
        service_fee_payment['尾款'], service_fee_payment['尾款时间'] = self.final_payment_method(service_fee_payment['尾款'])

        if service_fee_payment['总金额'].find('元') >= 0:
            lump_sum = service_fee_payment['总金额'][0:service_fee_payment['总金额'].find('.') + 3]
        else:
            lump_sum = service_fee_payment['总金额']
        item['page'] = {'commodity_list': self.commodity_venue(di, other, service, service_fee_payment),
                        'order': self.customer_information('基本信息', di['合同类型'], di, service, service_fee_payment, other),
                        'lump_sum': lump_sum,
                        'contract_number': di['合同编号'],  # 合同编号
                        'contract_time': di['签约时间'],
                        'approval_status': di['approval_status'],  # 0.不通过  1.通过  2.审批中
                        'receivedMoeny': other['（婚/会）已收定金'],
                        'remark': di['合同描述'] + di['宴席备注']
                        }
        if service['所选套餐']:
            if service['餐标']:
                self.ai[service['所选套餐']] = service['餐标']
        # yield item
        print(item)

    def commodity_venue(self, di, other, service, service_fee_payment):
        """
        处理商品和场地并装成一个列表
        :param di:
        :param other:
        :param page:
        :param service:
        :param service_fee_payment:
        :return:
        """
        # (type , title , text , di , service , service_fee_payment , other )
        page = [self.commodity_method(4, '宴会大厅', service['宴会大厅'], di, service, service_fee_payment, other),
                self.commodity_method(2, '所选套餐', service['所选套餐'], di, service, service_fee_payment, other),
                self.commodity_method(1, '白酒', service['白酒'], di, service, service_fee_payment, other),
                self.commodity_method(1, '啤酒', service['啤酒'], di, service, service_fee_payment, other),
                self.commodity_method(1, '饮料', service['饮料'], di, service, service_fee_payment, other),
                self.commodity_method(1, '(婚礼)主持人', other['（婚礼）主持人'], di, service, service_fee_payment, other),
                self.commodity_method(2, '(婚礼)摄影团队', other['（婚礼）摄影团队'], di, service, service_fee_payment, other),
                self.commodity_method(2, '(婚礼)摄像团队', other['（婚礼）摄像团队'], di, service, service_fee_payment, other),
                self.commodity_method(2, '(婚礼)跟妆团队', other['（婚礼）跟妆团队'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)快剪', other['（婚礼）快剪'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)花艺', other['（婚礼）花艺'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)迎宾牌', other['（婚礼）迎宾牌'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)桌卡数量', other['（婚礼）桌卡数量'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)烟雾机', other['（婚礼）烟雾机'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)水雾机', other['（婚礼）水雾机'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)仪式道具', other['（婚礼）仪式道具'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)客片分享', other['（婚礼）客片分享'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)婚礼统筹师', other['（婚礼）婚礼统筹师'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)婚礼灯光师', other['（婚礼）婚礼灯光师'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)婚礼音响师', other['（婚礼）婚礼音响师'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)婚礼LED大屏师', other['（婚礼）婚礼LED大屏师'], di, service, service_fee_payment,
                                      other),
                self.commodity_method(3, '(婚礼)婚礼音效师', other['（婚礼）婚礼音效师'], di, service, service_fee_payment, other),
                self.commodity_method(3, '(婚礼)宴会厅房长', other['（婚礼）宴会厅房长'], di, service, service_fee_payment, other)]
        # page = list(filter(None, page))
        return page

    def customer_information(self, *toppings):  # (title 0,text 1,di 2,service 3,service_fee_payment 4,other 5)
        """
        客资基本信息
        :param toppings:
        :return: dict(item)
        """
        item = WkCustomerItem()  # 1499295862206373889
        item['customer_source'] = toppings[2]['customer_source']
        item['business_type_name'] = toppings[2]['合同类型']
        item['customer_one'] = toppings[2]['bridegroom']
        item['customer_one_phone'] = toppings[2]['联系电话']
        item['customer_tow'] = toppings[2]['bride']
        item['date'] = toppings[2]['data']
        item['diningStandard'] = toppings[3]['餐标']
        if toppings[2]['签约时间段'] == '早场':
            item['date_period'] = 2
        elif toppings[2]['签约时间段'] == '午场':
            item['date_period'] = 3
        elif toppings[2]['签约时间段'] == '晚场':
            item['date_period'] = 4
        else:
            item['date_period'] = 1
        item['remark'] = toppings[5]['（婚礼）宴会标准备注'] + '（婚/会）酒水备注:{}'.format(toppings[5]['（婚/会）酒水备注'])  # 拿最后一个婚礼宴会备注
        if toppings[3]['主办方负责人'] == '郭梦如':
            item['sales'] = '喜堂 郭梦如'  # toppings[3]['主办方负责人']  匹配
        else:
            item['sales'] = toppings[3]['主办方负责人']  # toppings[3]['主办方负责人']  匹配
        item['number_of_tables'] = toppings[5]['（婚/会）桌数']
        item['table_preparation'] = toppings[5]['（婚/会）备桌']
        item['customize_one'] = '主办方:{}'.format(toppings[3]['主办方'])  # 基础信息自定义，拼接k，v字符串
        item['customize_tow'] = '（婚/会）酒水备注:{}'.format(toppings[5]['（婚/会）酒水备注'])  # 基础信息自定义，拼接k，v字符串
        item['customize_three'] = '新娘身份证:{}'.format(toppings[5]['新娘身份证'])
        item['customize_four'] = '新郎身份证:{}'.format(toppings[5]['新郎身份证'])
        item['customize_five'] = '（婚/会）送物品时间节点: {}'.format(toppings[5]['（婚/会）送物品时间节点'])
        item['customize_six'] = '（婚礼）家庭住址:{}'.format(toppings[5]['（婚礼）家庭住址'])

        return dict(item)

    def commodity_method(self, *toppings):  # (type 0,title 1,text 2,di 3,service 4,service_fee_payment 5,other 6)
        '''
        处理商品/场地数据
        :param toppings:
        :return: dict(item)
        '''
        if toppings[2] != '' and toppings[2].find('无') == -1 and toppings[2].find('否') == -1:
            item = WkCommodityItem()
            item['type'] = 2
            com = {
                '888商务宴': 1539903689329164290,  # $
                '1688商务宴': 1539904044272140290,  # $
                '2299梦幻套餐': 1539904224774012929,  # $
                '2288商务餐': 1539904420631232514,  # $
                '定制菜单': 1539904582296485889,  # $
                '1288商务宴': 1539904792770854913,  # $
                '不用餐': 1539905751752327170,  # $
                '1999焕新套餐': 1508721667651031041,  #
                '999玩味套餐': 1508721993451982849,  # 1508721667651031041
                '5888大人物': 1508722216916111361,  # $
                '1399恣享套餐': 1508722419500994561,  #
                '2699格调套餐': 1508722832275034113,  #
                '2399梦幻套餐': 1508723018367913985,  #
                '3199炫彩套餐': 1508723229291073537,  #
                '3888享乐套餐': 1508723632816672769,  #
                '4888全味套餐': 1508723837184135170,  # $
                '1699燎动套餐': 1508724030487023617,  #
                '(婚礼)主持人': 1539907951186624514,
                '(婚礼)摄影团队': 1539908245165391874,
                '(婚礼)摄像团队': 1539908452003299330,
                '(婚礼)跟妆团队': 1539908649215279106,
                '(婚礼)快剪': 1539908896897318913,
                '(婚礼)花艺': 1513763728465055745,
                '(婚礼)迎宾牌': 1513764023609839617,
                '(婚礼)桌卡数量': 1513764384286429186,
                '(婚礼)烟雾机': 1513764877465276417,
                '(婚礼)水雾机': 1513765286669963266,
                '(婚礼)仪式道具': 1539909384527101953,
                '(婚礼)客片分享': 1539909591222403073,
                '(婚礼)婚礼统筹师': 1513767060235603970,
                '(婚礼)婚礼灯光师': 1513767301617799169,
                '(婚礼)婚礼音响师': 1513767543130017793,
                '(婚礼)婚礼LED大屏师': 1539912045670383618,
                '(婚礼)婚礼音效师': 1513767795006361601,
                '(婚礼)宴会厅房长': 1513768096039948290,
                '白酒': 1539912433958076418,
                '啤酒': 1539912667123630081,
                '饮料': 1539912784320872449,
            }
            if toppings[0] == 1:  # title是商品名称/text是备注
                item['goodsId'] = com[toppings[1]]
                item['name'] = toppings[1]
                if toppings[1] == '白酒':  # 白酒特殊处理
                    item['remark'] = toppings[4]['白酒'] + toppings[5]['白酒品牌']
                    if toppings[5]['白酒瓶数']:
                        item['num'] = toppings[5]['白酒瓶数']
                    else:
                        item['num'] = 1
                    return dict(item)
                elif toppings[1] == '红酒':
                    if toppings[5]['红酒瓶数']:
                        item['num'] = toppings[5]['红酒瓶数']
                    else:
                        item['num'] = 1
                    return dict(item)
                elif toppings[1] == '啤酒':
                    if toppings[4]['啤酒']:
                        item['num'] = 1
                        item['remark'] = toppings[4]['啤酒']
                    else:
                        pass
                    return dict(item)
                elif toppings[1] == '饮料':
                    if toppings[4]['饮料']:
                        item['num'] = 1
                        item['remark'] = toppings[4]['饮料']
                    else:
                        pass
                    return dict(item)
                else:
                    item['num'] = 1
                    item['remark'] = toppings[2]
                    return dict(item)
            elif toppings[0] == 2:  # text是名称  # 套餐匹配不到  com[toppings[1]]
                if toppings[1] == '所选套餐':
                    item['name'] = toppings[2]
                    item['udpateUnitPrice'] = int(float(toppings[4]['餐标'])) * int(toppings[6]['（婚/会）桌数'])
                    try:
                        item['udpateUnitPrice'] = int(float(toppings[4]['餐标'])) * int(toppings[6]['（婚/会）桌数'])
                    except Exception as e:
                        print(e, '餐标没得')
                        pass
                    if toppings[2]:
                        item['goodsId'] = com[toppings[2]]
                    else:
                        pass
                    item['num'] = int(toppings[6]['（婚/会）桌数'])
                    item['remark'] = ''
                else:
                    item['name'] = toppings[1]
                    item['num'] = 1
                    item['remark'] = toppings[2]
                    item['goodsId'] = com[toppings[1]]
                return dict(item)
            elif toppings[0] == 3:
                if toppings[2].find('有') >= 0:
                    item['goodsId'] = com[toppings[1]]
                    item['name'] = toppings[1]
                    item['num'] = 1
                    item['remark'] = toppings[2]
                    return dict(item)
                elif toppings[2].find('套系') >= 0:
                    item['goodsId'] = com[toppings[1]]
                    item['name'] = toppings[1]
                    item['num'] = 1
                    item['remark'] = toppings[2]
                    return dict(item)
                elif toppings[2].find('是') >= 0:
                    item['goodsId'] = com[toppings[1]]
                    item['name'] = toppings[1]
                    item['num'] = 1
                    item['remark'] = toppings[2]
                    return dict(item)
                else:
                    item['goodsId'] = com[toppings[1]]
                    item['name'] = toppings[1]
                    item['num'] = 1
                    item['remark'] = toppings[2]
                    return dict(item)
            elif toppings[0] == 4:  # 处理场地
                if toppings[4]['宴会大厅']:
                    item['type'] = 1
                    site = {'告白气球': 1508363743175004161,
                            '金色大厅': 1508364600734011394,
                            '蒲公英约定': 1508365322896691201,
                            '蒲公英的约定': 1508365322896691201,
                            '屋顶': 1508367085364203522,
                            '星晴': 1508367732264292353,
                            '园游会': 1508368719729283073,
                            '仪式堂A（7:30-8:30）': 1513474873568432129,
                            '仪式堂B（8:30-9:30）': 1513476762347409409,
                            '威廉古堡': 1539904433319002113,
                            '西元前': 1539904718707834882,
                            '莫吉托': 1539904887079780354,
                            '迷迭香': 1539905027605741569,
                            '夜的第七章': 1539905816692736001,
                            '伊斯坦堡': 1539906051594731522,
                            '劳斯莱斯星空顶仪式堂': 1539907142222823425,
                            '园游会、告白气球': 1539907391985238018,
                            '威廉古堡VIP金色大厅': 1539907590392594434,
                            '飞跃仪式堂': 1539907898657161217,
                            '珊瑚海': 1539907985340841986,
                            '布拉格广场': 1539908074926981122,
                            '海岛店仪式堂': 1578566024675418114}
                    try:
                        item['goodsId'] = site[toppings[2]]
                    except Exception as e:
                        item['type'] = 3
                        print(e, '场地未找到')
                    item['name'] = toppings[4]['宴会大厅']
                    item['startTime'] = toppings[3]['data']
                    if toppings[3]['签约时间段'] == '早场':
                        item['timePeriod'] = 2
                    elif toppings[3]['签约时间段'] == '午场':
                        item['timePeriod'] = 3
                    elif toppings[3]['签约时间段'] == '晚场':
                        item['timePeriod'] = 4
                    else:
                        item['timePeriod'] = 1
                    try:
                        item['udpateUnitPrice'] = toppings[5]['婚礼费用']
                    except Exception as e:
                        item['udpateUnitPrice'] = toppings[5]['会议费用']
                        # print(e, '会议费用')
                    item['num'] = 1
                    item['remark'] = toppings[6]['（婚/会）酒水备注']
                return dict(item)
            else:
                pass

    def final_payment_method(self, final_payment):
        """
        处理尾款的拼接
        :param final_payment:
        :return:
        """
        if final_payment.find('.') > 0:
            n = final_payment[0:final_payment.find('.') + 3]
            if final_payment.split(n)[1].strip():
                final_payment_date = final_payment.split(n)[1].strip()[1:-1]
                # print('尾款', n, '尾款时间', final_payment_date)
                return n, final_payment_date
            else:
                final_payment_date = ''
                # print('尾款', n, '尾款时间', final_payment_date)
                return n, final_payment_date
        else:
            print('尾款未找到’.00‘这种标识符')
            n = final_payment
            final_payment_date = ''
            return n, final_payment_date

    def advance_method(self, pay_in_advance):
        """
        处理首付款的拼接
        :param pay_in_advance:
        :return:m,pay_in_advance_date
        """
        if pay_in_advance.find('.') > 0:
            m = pay_in_advance[0:pay_in_advance.find('.') + 3]
            if pay_in_advance.split(m)[1].strip():
                pay_in_advance_date = pay_in_advance.split(m)[1].strip()
                # print('首付款', m, '首付款时间', pay_in_advance_date)
                return m, pay_in_advance_date
            else:
                pay_in_advance_date = ''
                # print('首付款', m, '首付款时间', pay_in_advance_date)
                return m, pay_in_advance_date
        else:
            print('首付款未找到’.00‘这种标识符')
            m = pay_in_advance
            pay_in_advance_date = ''
            return m, pay_in_advance_date
